<template>
	<view>
		<u-navbar title="我的优惠券" :autoBack="true" :placeholder="true"></u-navbar>

		<view class="coupon-sec-body" :class="isIphoneX ? 'padding-bottom' : ''">
			<view class="coupon-list">
				<view class="coupon-item" v-for="(item, index) in couponList" :key="index">
					<view class="">
						<view class="coupon-item-box">
							<view class="coupon-pic">
								<!-- <image mode="aspectFit" src="../../static/images/other/yhq.png"></image> -->
								<view class="coupon-sale">
									100元
								</view>
								<view class="coupon-impose">
									满300元减免
								</view>
							</view>

							<view class="coupon-right">
								<view class="coupon-right-top">
									<view class="coupon-item-con">
										<view class="coupon-item-name">
											新人注册专享
										</view>
										<view class="yxq">
											有效期至 2023-12-31
										</view>
									</view>
									<view class="coupon-item-operation">
										<button class="coupon-item-btn">领取</button>
									</view>
								</view>

								<view class="sygz" @click="showSygz(item.id)">
									使用规则
								</view>
							</view>



						</view>

						<view class="dot"></view>
						<view class="dot2"></view>
					</view>

					<view class="sygzxq" v-show="false">
						1、本寿可用于门店现制啦啡类饮品 小黑杯系1列、酱香拿铁除外]事9.9元
						特价兑换优惠;<br />
						2、本乔不可用于小鼎杯系列饮品、游香章铁及丰冰啡类饮品;<br />
						3、本乔有效期以页页展示为准。请在有效期内尽快信用;<br />
						4、本行仅限[到店项订单信用，且表一次信用1张表1件饮品，不可抵扣配送费及另行选配的凤味睛袭、奶首、韩科等对加费用;<br />
						5、优惠乔全国门店通用 0快闪店][依游最区店]交通把纽店]特别声明不支
						持信用的门店不支持德用，下单前可与客服确认门店是否支持使,用6、本行不与其他优惠同事。
					</view>



				</view>
				<uni-load-more :status="status" v-if="couponList.length > 0 && pageCount > 1" />
			</view>
			<!-- <loading-cover ref="loadingCover"></loading-cover> -->
			<view v-if="isEmpty && couponList.length == 0" class="empty">
				<view class="iconfont iconwenzhangchaxun"></view>
				<text class="ns-text-color-gray">暂无优惠券</text>
				<button type="primary" @click="goIndex()">去首页逛逛吧</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				uid: wx.getStorageSync('userId'),
				isEmpty: false,
				couponList: [],
				pageIndex: 1,
				status: 'loading',
				pageCount: 0,
				indent: false, //防止初始化数据时，触发上拉加载
				isIphoneX: false //判断手机是否是iphoneX以上
			};
		},
		onReachBottom() {
			if (!this.indent) return;
		},
		onLoad() {
			uni.getSystemInfo({
				success: res => {
					if (res.model.search('iPhone X') != -1) {
						this.isIphoneX = true;
					}
				}
			});
		},
		onShow() {
			this.getmycouponlist();
		},
		// mixins: [http],
		methods: {
			async getmycouponlist() {
				let res = await this.$api.getmycouponlist({
					uid: this.uid
				});
				console.log(res);

				this.couponList = res.data.data;
				let couponList = this.couponList;
				for (let i = 0; i < couponList.length; i++) {

					couponList[i].check = true

				}
				this.couponList = couponList;

			},

			//去首页
			goIndex() {
				this.$util.redirectTo('/pages/index/index/index', {}, 'tabbar');
			},
			// jumpGetCoupon(id) {
			// 	this.$util.redirectTo('/pages/goods/coupon_receive/coupon_receive', {
			// 		coupon_type_id: id
			// 	});
			// },
			// 展示使用规则
			showSygz(id) {
				let couponList = this.couponList;
				for (let i = 0; i < couponList.length; i++) {

					if (couponList[i].id == id) {
						couponList[i].check = !couponList[i].check
					}
				}
				this.couponList = couponList;
				console.log(this.couponList)
			},
		}
	};
</script>

<style lang="scss" scoped>
	.coupon-item {
		margin: 15rpx 20rpx;
		padding: 10rpx 10rpx;
		background-color: #fff;
		position: relative;
		border-radius: 20rpx;

		.coupon-item-box {
			&.completion-collection {
				// background-color: $ns-bg-color-gray;

				view {
					color: #999 !important;
				}
			}

			&:after {
				content: '';
				position: absolute;
				top: -14rpx;
				left: 514rpx;
				z-index: 3;
				width: 30rpx;
				height: 30rpx;
				background-color: #fff;
				border-radius: 50%;
			}

			&:before {
				content: '';
				position: absolute;
				bottom: -14rpx;
				left: 514rpx;
				z-index: 3;
				width: 30rpx;
				height: 30rpx;
				background-color: #fff;
				border-radius: 50%;
			}

			position: relative;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 16rpx;
			border-radius: 12rpx;
			// background-color: lighten($base-color, 45%);

			.coupon-item-con {
				width: 320rpx;
				margin-right: auto;
				padding: 0 20rpx;

				// height: 156rpx;
				line-height: 1;

				// font-size: $ns-font-size-base;

				text {
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					display: inherit;
				}
			}

			.coupon-item-operation {
				margin-right: 10rpx;
				color: #111;
				// color: $base-color;
				// font-size: $ns-font-size-base;
			}

			.coupon-item-name {
				margin-top: 14rpx;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			.num {
				margin-left: 4rpx;
				margin-right: 10rpx;
				// font-size: $ns-font-size-lg + 12rpx;
				font-weight: 600;
				display: inline-block !important;
				overflow: initial !important;
			}
		}
	}

	.coupon-item-btn {
		height: 60rpx;
		line-height: 60rpx;
		font-size: 24rpx;
		margin: 0;
		background-color: #111;
		color: white;
		padding: 0 20rpx;
		width: 120rpx;
		border-radius: 50rpx;
		margin-top: 20rpx;
	}

	.dot {
		width: 20rpx;
		height: 20rpx;
		// background-color: #111;
		background-color: #f6f6f6;
		border-radius: 10rpx;
		position: absolute;
		top: -10rpx;
		left: 178rpx;
	}

	.dot2 {
		width: 20rpx;
		height: 10rpx;
		// background-color: #111;
		background-color: #f6f6f6;
		border-top-left-radius: 20rpx;
		border-top-right-radius: 20rpx;
		position: absolute;
		btttom: -10rpx;
		left: 178rpx;
	}

	.padding-bottom {
		padding-bottom: 68rpx !important;
	}

	.coupon-pic {
		width: 144rpx;
		height: 144rpx;
		margin-right: 15rpx;
		text-align: center;
		font-weight: 700;

		.coupon-sale {
			color: #f79017;
			margin-top: 40rpx;
			font-size: 36rpx;
		}

		.coupon-impose {
			font-size: 22rpx;
			color: #333;
			line-height: 60rpx;
		}
	}

	.coupon-right-top {
		display: flex;
		border-bottom: 1rpx dotted #999;
	}

	.sygz {
		margin-left: 20rpx;
		font-size: 22rpx;
		margin-top: 10rpx;
	}

	.sygzxq {
		// border-top: 1rpx solid red;
		padding-left: 200rpx;
		font-size: 20rpx;
		padding-top: 10rpx;
		padding-right: 20rpx;
	}

	.yxq {
		color: #f79017;
		font-size: 24rpx;
		line-height: 60rpx;
		margin-bottom: 10rpx;
	}
</style>